//
//  ChangePlayerMenu.h
//  CChangePlayerMenu: Main class of the game
//
//  Created by Enric Vergara on 20.10.12. 
//  Copyright OWLAB 2010. All rights reserved.
// Import the interfaces

#import "ChangePlayerMenu.h"
#import "SoundManager.h"
#import "Player.h"
#import "PokerTexasHoldem.h"

// CRaiseMenu implementation
@implementation CChangePlayerMenu



// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if ((self = [super init]))
    {
        m_Player = NULL;
        //CGSize screenSize = [[CCDirector sharedDirector] winSize];
        CGPoint center = CGPointMake(0,0);
        //Definim el tapete del joc
        m_Background = [CCSprite spriteWithFile:@"menuExit_background.JPG"]; 
        m_Background.position =center;
        [self addChild:m_Background];

       [CCMenuItemFont setFontName:@"Arial"];
        [CCMenuItemFont setFontSize:40];
        m_Button_Player_Local = [CCMenuItemFont itemFromString:@"(Local)" target:self selector:@selector(Choose_Player_Local:)];
		m_Button_Player_Local.position =  CGPointMake( 200, -20);
        
        m_Button_Player_AI = [CCMenuItemFont itemFromString:@"(AI)" target:self selector:@selector(Choose_Player_AI:)];
        m_Button_Player_AI.position =  CGPointMake(0, -20);
        
        m_Button_Player_Network = [CCMenuItemFont itemFromString:@"(Network)" target:self selector:@selector(Choose_Player_Network:)];
        m_Button_Player_Network.position =  CGPointMake(-200, -20);


        m_Button_Cancel = [CCMenuItemFont itemFromString:NSLocalizedString(@"Cancel", @"") target:self selector:@selector(Cancel:)];
        m_Button_Cancel.position =  CGPointMake( 0, -70);
        
        
        // create the menu using the items
        m_Menu = [CCMenu menuWithItems:m_Button_Player_Local, m_Button_Player_AI, m_Button_Player_Network, m_Button_Cancel, nil];
        m_Menu.position = center;
        [self addChild:m_Menu];
        m_Menu.visible = true;

        //label indicant --> Choose type of Player:
        m_sTitleLabel = [CCLabel labelWithString:@"Choose type Player:"  fontName:@"Arial" fontSize:40];
        [m_sTitleLabel setColor:ccc3(0,0,0)];
        [m_sTitleLabel setPosition:CGPointMake(center.x,center.y + 50)];
        [self addChild: m_sTitleLabel];
        
        
		// must be enabled if you want to receive touch events!
		self.isTouchEnabled = YES;
	}
	return self;
}

-(void) setPlayer:(CPlayer*) player
{
    m_Player = player;
}

-(void) activeMenu
{
    self.visible = true;
    
    m_bButton_Player_AI         = 
    m_bButton_Player_Local      = 
    m_bButton_Player_Network    = true;
    
    m_Button_Player_AI.opacity          =
    m_Button_Player_Local.opacity       =
    m_Button_Player_Network.opacity     = 255;
    
    switch (m_Player->m_eTypePlayer)
    {
        case PLAYER_AI:
            m_Button_Player_AI.opacity = 100;
            m_bButton_Player_AI = false;
            break;
        case PLAYER_LOCAL:
            m_Button_Player_Local.opacity = 100;
            m_bButton_Player_Local = false;
            break;
        case PLAYER_NETWORK:
            m_Button_Player_Network.opacity = 100;
            m_bButton_Player_Network = false;
            break;
    }
}

-(void) ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{

}

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

-(void) Choose_Player_AI: (id) sender
{
    if (!self.visible  || !m_bButton_Player_AI) return;

    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_NEXT];
    [m_Player->m_pPokerGame changePlayerType:m_Player->m_uiID TypeOfPlayer:PLAYER_AI];
    self.visible = false;
}

-(void) Choose_Player_Local: (id) sender
{
    if (!self.visible || !m_bButton_Player_Local) return;
    
    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_NEXT];
    [m_Player->m_pPokerGame changePlayerType:m_Player->m_uiID TypeOfPlayer:PLAYER_LOCAL];
    self.visible = false;
}

-(void) Choose_Player_Network: (id) sender
{
    if (!self.visible || !m_bButton_Player_Network) return;
    
    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_NEXT];
    [m_Player->m_pPokerGame changePlayerType:m_Player->m_uiID TypeOfPlayer:PLAYER_NETWORK];
    self.visible = false;
}

-(void) Cancel: (id) sender
{
    if (!self.visible) return;
    
    self.visible = false;    
    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_CANCEL];
}


// on "dealloc" you need to release all your retained objects
-(void) dealloc
{
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end
